﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CpuSimulator.Instructions
{
    /// <summary>
    /// SLL(Shift Left Logical) 将rs1的值逻辑左移rs2中的值，并将结果写入rd
    /// ________________________________________________________________________________________________________________________________________________
    /// |_______________Fun7___________|_______rs2,5位_______|_________rs1,5位______|_Func3______|_______rd,5位________|_____OPCODE 7位____________|
    /// | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 09 | 08 | 07 | 06 | 05 | 04 | 03 | 02 | 01 | 00 |
    /// |                   0000000              |             rs2               |            rs1                 |    001          |            rd                 |            0110011                     |
    /// </summary>
    public class SLL : Instruction
    {
        public override void Execute(Cpu cpuinfo)
        {
            var newVal = cpuinfo.Registers[this.Rs1].Value << cpuinfo.Registers[this.Rs2].Value;
            cpuinfo.Registers[this.Rd].SetValue(newVal);
            cpuinfo.InvodeRegisterChange(this.Rd, newVal.ToString("X8"));
        }
    }
}
